<?php
namespace App\Http\Controllers\Admin;

use App\Business;
use App\Http\Controllers\Controller;
use App\User;
use App\UserCoinLog;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Intervention\Image\Facades\Image;


class UserController extends Controller
{
	public function log( Request $request )
	{
		$type  = $request->input('t') ?: 1;
		$user  = User::find( $request->input('id') );

		$logs = UserCoinLog::where('user_id', $user->id)->where('type', $type)->orderBy('id', 'desc')->paginate(15);

		$bussiness[] = '-';
        foreach (Business::get() as $item) {
            $bussiness[] = $item->name;
        }

        $user->XYB = UserCoinLog::totalXyb( $user->id );
        $user->JB = UserCoinLog::totalJb( $user->id );

		$data['user'] = $user;
		$data['logs'] = $logs;
		$data['bussiness'] = $bussiness;
		$data['params'] = $request->all();

		$request->flash();

		return view('admin.userlog', $data);
	}
}